/**
 * 
 */
package handwritten.character;

import java.io.Serializable;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.ArrayList;

/**
 * @author tioz
 *
 */
public class CharacterCollection<E extends HandWritten> implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Hashtable<String,ArrayList<E>> collection;
	
	private Class<E> type;
	private String collecType;
	
	CharacterCollection(Class<E> key){
		this.type = key;
		collection = new Hashtable<String,ArrayList<E>>();
		collecType= "default";
	}
	
	CharacterCollection(Class<E> key,String type){
		this.type = key;
		collection = new Hashtable<String,ArrayList<E>>();
		collecType= type;
	}
	
	public void addSample(E newEntry){
				
		ArrayList<E>  samples= collection.get(newEntry.getId());
		if(samples == null){
			samples = new ArrayList<E>();
			collection.put(newEntry.getId().toString(),samples);
		}
		samples.add(newEntry);
	}
	
	CharacterCollection<E> createCollection(){
		return new CharacterCollection<E>(type);
	}
	
	CharacterCollection<E> createCollection(String name){
		return new CharacterCollection<E>(type,name);
	}
	
	public Hashtable<String,ArrayList<E>> getCollection()
	{
		return collection;
	}
	
	public Class<? extends HandWritten> getType() {
		return type;
	}

	public Enumeration<String> keys(){
		return collection.keys();
	}
	
	public int size(String key){
		return collection.get(key).size();		
	}
	
	public E get(String key,int index){
		return collection.get(key).get(index);
	}
	


	/**
	 * @return the collecType
	 */
	public String getCollecType() {
		return collecType;
	}

	/**
	 * @param collecType the collecType to set
	 */
	public void setCollecType(String collecType) {
		this.collecType = collecType;
	}

	/**
	 * @return
	 */
	public int size() {
		return collection.size();
	}

	/**
	 * 
	 */
	public void clear() {
		collection.clear();	
	}
	
}
